function callback(fun,argum){
	fun(argum);
}

//删除类型框
function delTypeBox(){
	$('input[name="publish_type"]').val( 0 );
	$('.talkPop').remove();
}


$(document).ready(function(){
});

tweet.prototype={
		//初始化微博发布
		init:function(option){
			var Interval;
			$("#publish_type_content_before").html("<span>添加：</span><a href=\"javascript:void(0)\" target_set=\"content_publish\" onclick=\"ui.emotions(this)\" class=\"a52\"><img class=\"icon_add_face_d\" src=\"__BASE__/Public/images/zw_img.gif\" />表情</a> <a href=\"javascript:void(0)\" onclick=\"addtheme()\" class=\"a52\"><img class=\"icon_add_topic_d\" src=\"__BASE__/Public/images/zw_img.gif\" />话题</a> <a href=\"javascript:void(0)\" onclick=\"tweet.plugin.image.click(169)\" class=\"a52\"><img class=\"icon_add_img_d\" src=\"__BASE__/Public/images/zw_img.gif\" />图片</a> <a href=\"javascript:void(0)\" onclick=\"tweet.plugin.video.click(221)\" class=\"a52\"><img class=\"icon_add_video_d\" src=\"__BASE__/Public/images/zw_img.gif\" />视频</a> <a href=\"javascript:void(0)\" onclick=\"tweet.plugin.music.click(271)\" class=\"a52\"><img class=\"icon_add_music_d\" src=\"__BASE__/images/zw_img.gif\" />音乐</a>");

			$("#content_publish").keypress(function(){
				tweet.checkInputLength(this,140);
			}).blur(function(){
				clearInterval(Interval);
				tweet.checkInputLength(this,140);
			}).focus(function(){
				//微博字数监控
				clearInterval(Interval);
			    Interval = setInterval(function(){
			    	tweet.checkInputLength('#content_publish',140);
				},300);
			});
			tweet.checkInputLength('#content_publish',140);
			shortcut('ctrl+return',	function(){tweet.do_publish();},{'target':'miniblog_publish'});
		},
		//发布前的检测
		before_publish:function(){
			
			if( $.trim( $('#content_publish').val() ) == '' || $.trim($('#datePicker').val()) ==''){
	            alert('内容和发送时间不能为空');		
				return false;
			}
			return true;
		},
		//发布操作
		do_publish:function(){
			if( tweet.before_publish() ){
				tweet.textareaStatus('sending');
				var options = {
				    success: function(txt) {
				      if(txt){
				    	   tweet.after_publish(txt);
				      }else{
		                  alert( '发布失败' );
				      }
					}
				};		
				$('#miniblog_publish').ajaxSubmit( options );
			    return false;
			}
		},
		//发布后的处理
		after_publish:function(txt){
			delTypeBox();
		    $("#feed_list").prepend( txt ).slideDown('slow');
		    $('#miniblog_publish').clearForm();
		    tweet.upCount('tweet');
		    ui.success('微博发布成功');
		    tweet.checkInputLength('#content_publish',140);
		},
		//发布按钮状态
		textareaStatus:function(type){
			var obj = $('#publish_handle');
			if(type=='on'){
				obj.removeAttr('disabled').attr('class','btn_big hand');
			}else{
				obj.attr('disabled','true').attr('class','btn_big_disable hand');
			}
		},
		//删除一条微博
		deleted:function(tweet_id){
			$.post(mk_url("Tweet/delete"),{id:tweet_id},function(txt){
				if( txt ){
					$("#list_li_"+tweet_id).slideUp('fast');
					tweet.downCount('tweet');
				}else{
					alert('删除失败');
				}
			});
		},
		//检查字数输入
		checkInputLength:function(obj,num){
			var len = getLength( $(obj).val() );
			var wordNumObj = $('.wordNum');
			
			if(len==0){
				wordNumObj.css('color','').html('你还可以输入<strong id="strconunt">'+ (num-len) + '</strong>字');
				tweet.textareaStatus('off');
			}else if( len > num ){
				wordNumObj.css('color','red').html('已超出<strong id="strconunt">'+ (len-num) +'</strong>字');
				tweet.textareaStatus('off');
			}else if( len <= num ){
				wordNumObj.css('color','').html('你还可以输入<strong id="strconunt">'+ (num-len) + '</strong>字');
				tweet.textareaStatus('on');
			}
		},
		publish_type_box:function(type_num,content,mg_left){
			var html = '<div class="talkPop"><div  style="position: relative; height: 7px; line-height: 3px;">'
			     + '<img class="talkPop_arrow" style="margin-left:'+ mg_left +'px;position:absolute;" src="__BASE__/Public/images/zw_img.gif" /></div>'
	             + '<div class="talkPop_box">'
				 + '<div class="close" id="tweet_close_handle"><a href="javascript:void(0)" class="del" onclick=" delTypeBox()" > </a></div>'
				 + '<div id="publish_type_content">'+content+'</div>'
				 + '</div></div>';
			$('input[name="publish_type"]').val( type_num );
			$('div .talkPop').remove();
			$("#publish_type_content_before").after( html );		
		}
}
tweet = new tweet();

tweet.plugin = {}